package com.dog.basics.api.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiCouponFromDto;
import com.dog.basics.bean.vo.api.mtkj.ApiCouponInfoVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券领用表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/api/coupon")
@Api(value = "优惠券领用", tags = SwaggerConstants.API_ALL)
@AllArgsConstructor
public class MtCouponController {
    private final IMtCouponService couponService;

    /**
     * 分页查询用户优惠券
     * 1.查询用户所有优惠券
     * 2.查询用户某个商铺的优惠券
     *
     * @param page
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "用户优惠券", tags = SwaggerConstants.API_COUPON)
    public R<IPage<ApiCouponInfoVo>> findCoupon(PageParam page, ApiCouponFromDto dto) {
        return R.ok(couponService.getPageList(page, dto));
    }

    /**
     * 用户领取优惠券
     *
     * @param couponId
     * @return
     */
    @PostMapping("/getCoupon/{couponId}")
    @ApiOperation(value = "领取优惠券", tags = SwaggerConstants.API_COUPON)
    @ApiImplicitParam(value = "优惠券Id", name = "couponId", dataType = "Long", required = true)
    public R<Boolean> getCoupon(@Valid  @PathVariable("couponId") Long couponId) {
        return R.ok(couponService.saveCoupon(couponId));
    }

    /**
     * 删除优惠券
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCoupon/{id}")
    @ApiOperation(value = "删除用户优惠券", tags = SwaggerConstants.API_COUPON)
    @ApiImplicitParam(value = "用户优惠券id", name = "id", dataType = "Long", required = true)
    public R<Boolean> deleteCoupon(@Valid @PathVariable("id") Long id) {
        return R.ok(couponService.deleteCoupon(id));
    }

}
